package com.chen.bpsptsystem.controller.manger;

import com.chen.bpsptsystem.common.ServerResponse;
import com.chen.bpsptsystem.po.User;
import com.chen.bpsptsystem.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chen
 * 用户管理
 */
@RestController
@RequestMapping("/back/user/")

public class UserController {

    @Resource
    private IUserService userService;

    /**
     * 用户list
     *
     * @param pn
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public ServerResponse list(@RequestParam(value = "pn", name = "pn", defaultValue = "1") Integer pn,
                               @RequestParam(value = "pageSize", name = "pageSize", defaultValue = "10") Integer pageSize) {
        return userService.list(pn, pageSize);
    }

    /**
     * @param user
     * @param clazzId 分配班级
     * @return
     */
    @PostMapping("add")
    public ServerResponse add(@RequestBody User user, String clazzId) {
        return userService.add(user, clazzId);
    }

    /**
     * 用户删除
     *
     * @param userId
     * @return
     */
    @PostMapping("delete")
    public ServerResponse delete(Integer userId) {
        return userService.delete(userId);
    }

    /**
     * 修改班级
     *
     * @param clazzId
     * @param userId
     * @return
     */
    @PostMapping("editUserClazz")
    public ServerResponse editUserClazz(String clazzId, Integer userId) {
        return userService.editUserClazz(userId, clazzId);
    }



}
